env.setErrorMessageBoxEnabled(true) -- for debug
--SOUND_EXTRACTION_CALL = USERSOUND:New("直升机呼叫division.ogg")
--SOUND_AFAC_CALL = USERSOUND:New("15秒division.ogg")

GRIFFIN_AFAC = SPAWN:New("GRIFFIN AFAC #001"):InitRepeat():InitKeepUnitNames(true):OnSpawnGroup(
function(group)
  MessageToAll("==============>\n格里芬空中支援：无人侦察机已经部署，正在前往目标地域。\n无线电:131AM\n呼号: Pontiac 1-1\n==============<", 10, "格里芬空中支援")
  SOUND_AFAC_CALL:ToAll()
end)

local cargoTrucks = {}

-- 运输卡车
for i=1,9,1 do
  local temp = SPAWN:New("GRIFFIN PLAYERTRANSPORT-" .. tostring(i)):InitKeepUnitNames(true)
  table.insert(cargoTrucks, temp)
  temp:Spawn()
end

-- 运输卡车生成函数
local function cargoTruckSpawn()
  for i, v in ipairs(cargoTrucks) do
    v:ReSpawn()
  end
  MessageToAll("==============>\n格里芬后勤中心：\n 完成后勤补给车队以及JTAC的重新部署\n==============<",MsgTime,MsgName)
  SOUND_EXTRACTION_CALL:ToAll()
end


PLAYER_TANKS_SOUTH = SPAWN:New("GRIFFIN PLAYERTANK #001"):InitKeepUnitNames(true)
PLAYER_JTAC_SOUTH_MOUNTAIN = SPAWN:New("GRIFFIN PLAYERJTAC #001-1"):InitKeepUnitNames(true)
PLAYER_ARTY_SOUTH = SPAWN:New("GRIFFIN PLAYERARTY #001"):InitKeepUnitNames(true)
PLAYER_AA_SOUTH = SPAWN:New("GRIFFIN PLAYERAA #001"):InitKeepUnitNames(true)

-- 初始化复活
PLAYER_TANKS_SOUTH:Spawn()
PLAYER_JTAC_SOUTH_MOUNTAIN:Spawn()
PLAYER_ARTY_SOUTH:Spawn()
PLAYER_AA_SOUTH:Spawn()
GRIFFIN_AFAC:Spawn()

function respawnGRIFFINGROUP( type )
  local temp = type["val"]
  if temp == "TANK_SOUTH" then
    PLAYER_TANKS_SOUTH:ReSpawn()
  end
  
  if temp == "JTAC_SOUTH" then
    cargoTruckSpawn()
    PLAYER_JTAC_SOUTH_MOUNTAIN:ReSpawn()
  end
  
  if temp == "ARTY_SOUTH" then
    PLAYER_ARTY_SOUTH:ReSpawn()
  end
  
  if temp == "AA_SOUTH" then
    PLAYER_AA_SOUTH:ReSpawn()
  end
  
  if temp == "AFAC_SOUTH" then
    GRIFFIN_AFAC:ReSpawn()
  end
  
end

PARENTMENU_GRIFFIN_GROUND = MENU_MISSION:New("格里芬地面人形部队控制")
MENU_TANKS_SOUTH = MENU_MISSION_COMMAND:New("重新部署坦克车队", PARENTMENU_GRIFFIN_GROUND, respawnGRIFFINGROUP, {val = "TANK_SOUTH"})
MENU_JTAC_SOUTH = MENU_MISSION_COMMAND:New("重新部署JTAC \ 运输车队", PARENTMENU_GRIFFIN_GROUND, respawnGRIFFINGROUP, {val = "JTAC_SOUTH"})
MENU_ARTY_SOUTH = MENU_MISSION_COMMAND:New("重新部署火炮", PARENTMENU_GRIFFIN_GROUND, respawnGRIFFINGROUP, {val = "ARTY_SOUTH"})
MENU_AA_SOUTH = MENU_MISSION_COMMAND:New("重新部署防空", PARENTMENU_GRIFFIN_GROUND, respawnGRIFFINGROUP, {val = "AA_SOUTH"})
MENU_AFAC_SOUTH = MENU_MISSION_COMMAND:New("重新部署无人侦察机 \ 前进空中指挥", PARENTMENU_GRIFFIN_GROUND, respawnGRIFFINGROUP, {val = "AFAC_SOUTH"})

_SETTINGS:SetPlayerMenuOff()
env.setErrorMessageBoxEnabled(false)